﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Utils;

public partial class order_index : FBasePage
{
    // Fields

    public Maticsoft.BLL.orderdetail detailbll = new Maticsoft.BLL.orderdetail();
    public List<Maticsoft.Model.orderdetail> detaillist = new List<Maticsoft.Model.orderdetail>();

    public Maticsoft.BLL.Order orderbll = new Maticsoft.BLL.Order();
    public List<Maticsoft.Model.Order> orderlist = new List<Maticsoft.Model.Order>();
    public string pagenum = "1";
    public string pay = "";
    public bool result = false;
    public string strpage;
    public Maticsoft.BLL.UserInfo userbll = new Maticsoft.BLL.UserInfo();

    // Methods
    public void GetOrder()
    {
        int num;
        Maticsoft.Model.UserInfo info = new Maticsoft.Model.UserInfo();
        string whereString = "User_id=" + this.userbll.Getuserid(base.UserName) + " and State!='cancel' and State!='refund'";
        if ((base.Request["pay"] != null) && (base.Request["pay"] != ""))
        {
            this.pay = base.Request["pay"].ToString().Replace("'", "");
            whereString = whereString + " and State='" + this.pay + "'";
        }
        this.orderlist = this.orderbll.SearchOrder(30, Convert.ToInt32(this.pagenum), "*", "", whereString, out num);
        if (this.orderlist.Count == 0)
        {
            this.strpage = "对不起，没有相关数据";
        }
        else if (num >= 30)
        {
            this.strpage = this.orderbll.GetOrderPageStr(num, Convert.ToInt32(this.pagenum), 30, this.pay);
        }
    }

    public void getResultTeam(int teamId)
    {
        Maticsoft.Model.Team model = new Maticsoft.Model.Team();
        model = new Maticsoft.BLL.Team().GetModel(teamId);
        if (model != null)
        {
            if (model.End_time < DateTime.Now)
            {
                this.result = true;
            }
            else
            {
                this.result = false;
            }
        }
    }

    public string GetStyle(string s, string style)
    {
        string str = "";
        if (s == style)
        {
            str = "class='current'";
        }
        return str;
    }

    public string GetTeam(string id, string orderid)
    {
        string str = "";
        Maticsoft.Model.Team model = new Maticsoft.Model.Team();
        Maticsoft.BLL.Team team2 = new Maticsoft.BLL.Team();
        model = team2.GetModel(Convert.ToInt32(id));
        if (model != null)
        {
            this.getResultTeam(model.Id);
            return string.Concat(new object[] { "<a class='deal-title' href='/team.aspx?id=", model.Id, "' target='_blank'>", model.Title, "</a>" });
        }
        this.detaillist = this.detailbll.Searchorderdetail(Convert.ToInt32(orderid));
        if (this.detaillist != null)
        {
            int num = 0;
            foreach (Maticsoft.Model.orderdetail orderdetail in this.detaillist)
            {
                this.getResultTeam(Convert.ToInt32(orderdetail.Teamid));
                num++;
                object obj2 = str;
                str = string.Concat(new object[] { obj2, "<a class='deal-title' href='../team.aspx?id=", orderdetail.Teamid, "' target='_blank'>", num, ":" });
                str = str + ((team2.GetModel(Convert.ToInt32(orderdetail.Teamid)) == null) ? "" : team2.GetModel(Convert.ToInt32(orderdetail.Teamid)).Title);
                str = str + "</a><br>";
            }
            return str;
        }
        return "";
    }

    public bool Gettuan(int Id, string pay)
    {
        bool flag = false;
        Maticsoft.Model.Team model = new Maticsoft.Model.Team();
        model = new Maticsoft.BLL.Team().GetModel(Id);
        if ((model != null) && ((model.End_time < DateTime.Now) && (pay == "unpay")))
        {
            flag = true;
        }
        return flag;
    }

    protected override void OnLoad(EventArgs e)
    {
        if (!(this.Page.User.Identity.IsAuthenticated && !(this.Page.User.Identity.Name == "")))
        {
            base.Response.Redirect("/account/Login.aspx");
        }
        base.OnLoad(e);
        this.MyWebside1.Select = "order";
        if (base.Request["pgnum"] != null)
        {
            if (Utility.IsNum(base.Request["pgnum"].ToString()))
            {
                this.pagenum = base.Request["pgnum"].ToString();
            }
            else
            {
                this.SetError("您输入的参数非法");
            }
        }
        this.GetOrder();
    }

}